function capturePhoto() {
          navigator.camera.getPicture(onSuccessImage, onErrorImage, 
            { 
                quality: 100, 
                targetWidth: 250, 
                targetHeight: 250 
            }
          );
        }

        function getPhoto() {
          navigator.camera.getPicture(onSuccessImage, onErrorImage, 
            { 
                quality: 100, 
                destinationType: Camera.DestinationType.FILE_URI, 
                sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
                targetWidth: 250,
                targetHeight: 250
            }
          );
        }


function onSuccessImage(imageURI) {
            $('#image').attr('src', imageURI);
            $('#message').html('Image location: ' + imageURI);
                
            var db; // inserisco i dati nel database
      		db = getDatabase(); //database.js

      		db.transaction(function(tx) {
            	tx.executeSql("CREATE TABLE IF NOT EXISTS myDiary (id INTEGER PRIMARY KEY AUTOINCREMENT, name, description, type, latitude, longitude, full_path, date, size )");
      		}, databaseError, getItemsImage); //database.js


       		// inserisco il nuovo elemento
           	var name = "";
         	var description = "";
        	var type = 'image';
         	var latitude = "";
          	var longitude = "";
           	var full_path = imageURI;
           	tempData = new Date();
         	var date = tempData.toUTCString();
            var size = "";                  

          	// ottengo l'attuale posizione per poterla registrare
        	navigator.geolocation.getCurrentPosition(function(position) {
              	latitude = position.coords.latitude;
               	longitude = position.coords.longitude;
            }, onErrorGeo);


        	db.transaction(function(tx) {
               	tx.executeSql('INSERT INTO myDiary (name, description, type, latitude, longitude, full_path, date, size) VALUES ("' + name + '", "' + description + '", "' + type + '", "' + latitude + '", "' + longitude + '", "' + full_path + '", "' + date + '", "' + size + '")');
       		}, databaseError, getItemsImage);
                
        }
        
        function onErrorImage(message) {
          $('#message').html(message);
        }